Expand description
Streaming iterators.
The iterator APIs in the Rust standard library do not allow elements to be yielded which borrow
from the iterator itself. That means, for example, that the std::io::Lines
iterator must
allocate a new String
for each line rather than reusing an internal buffer. The
StreamingIterator
trait instead provides access to elements being iterated over only by
reference rather than by value.
StreamingIterator
s cannot be used in Rust for
loops, but while let
loops offer a similar
level of ergonomics:
ⓘ
while let Some(item) = iter.next() {
}
However, make sure to only use the above form with a mutable reference to an existing iterator,
not with an expression that creates an iterator.
For example, the following code will loop forever over the first element of the array:
use streaming_iterator::{convert, StreamingIterator};
let array = [0, 1, 2, 3];
while let Some(item) = convert(array.iter()).next() {
}
While the standard Iterator
trait’s functionality is based off of the next
method,
StreamingIterator
’s functionality is based off of a pair of methods: advance
and get
. This
essentially splits the logic of next
in half (in fact, StreamingIterator
’s next
method
does nothing but call advance
followed by get
).
This is required because of Rust’s lexical handling of borrows (more specifically a lack of
single entry, multiple exit borrows). If StreamingIterator
was defined like Iterator
with
just a required next
method, operations like filter
would be impossible to define.
A streaming iterator that concatenates two streaming iterators
A normal, non-streaming, iterator which converts the elements of a streaming iterator into owned
values by cloning them.
A streaming iterator which yields elements from a normal, non-streaming, iterator.
A streaming iterator which yields elements from an iterator of mutable references.
A streaming iterator which yields elements from an iterator of references.
A normal, non-streaming, iterator which converts the elements of a streaming iterator into owned
values by copying them.
A simple iterator that returns nothing.
A streaming iterator which filters the elements of a streaming iterator with a predicate.
An iterator which both filters and maps elements of a streaming iterator with a closure.
A regular, non-streaming iterator which both filters and maps elements of a streaming iterator with a closure.
A streaming iterator that maps elements to iterators with a closure and then yields the
concatenation of the obtained iterators
A streaming iterator that flattens nested streaming iterators.
A simple iterator that returns items from a function call.
A streaming iterator which is well-defined before and after iteration.
A streaming iterator that calls a function with element before yielding it.
A streaming iterator which transforms the elements of a streaming iterator.
A regular, non-streaming iterator which transforms the elements of a streaming iterator.
A regular, non-streaming iterator which transforms the elements of a mutable streaming iterator.
A streaming iterator which transforms the elements of a streaming iterator.
A simple iterator that returns exactly one item.
A simple iterator that returns exactly one item from a function call.
A normal, non-streaming, iterator which converts the elements of a streaming iterator into owned
versions.
A simple iterator that repeats an item endlessly.
A simple iterator that endlessly returns items from a function call.
A streaming iterator which returns elements in the opposite order.
A streaming iterator which skips a number of elements in a streaming iterator.
A streaming iterator which skips initial elements that match a predicate
An iterator where each successive item is computed from the preceding one.
A streaming iterator which only yields a limited number of elements in a streaming iterator.
A streaming iterator which only returns initial elements matching a predicate.
A streaming iterator which returns overlapping mutable subslices of length size
.
Turns a normal, non-streaming iterator into a streaming iterator.
Turns an iterator of mutable references into a streaming iterator.
Turns an iterator of references into a streaming iterator.
Creates an empty iterator.
Creates an iterator that returns items from a function call.
Creates an iterator that returns exactly one item.
Creates an iterator that returns exactly one item from a function call.
Creates an iterator that returns an item endlessly.
Creates an iterator that endlessly returns items from a function call.
Creates an iterator where each successive item is computed from the preceding one.
Creates an iterator over all contiguous windows of length size
in a mutable slice
.